<?php
/*
 * @Author: KingMin 
 * @Date: 2022-3-12 11:42:04
 * @Last Modified by:   KingMin 
 * @Last Modified time: 2022-3-12 11:42:09
 * @The authors website: https://www.kingmin.cn  
 */
  @require_once '../../init.php';
 
    // 清除缓存 'options'
    function clearCache($cn=''){
        $CACHE = Cache::getInstance();
        if(!$cn){
            $user = isLogin();
            if($user){
                if($user['role_scope']!=1){
                   userGenxin();
                   ajaxReturn (200,'更新登录缓存信息成功');
                }
            }else{
                ajaxReturn (410000,'账号未登录',$user);
            }
            $log_type="cache";
            $log_title="清除缓存";
            $log_url='/admin/clearCache';
            $log_data['token']=$user['token'];
            $log_data['data']="";
            $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
            @$msg= '【'.$user['nickName'].'】'.$log_title.'成功';
            @$caozuorz=addOperationLog($user['uid'],"0","1",$log_type,$log_title,$log_url,$log_data,"true","0",$msg);
            userGenxin();
            $dt=$CACHE->updateCache();
        }else{
            $dt=$CACHE->updateCache($cn);
        }
        return true;
    }
    // 获取数据表列表
    function getDataBaseList($dt=[]){
        $user = isLogin();
        $uid=$user['uid'];
        if(@$user['role_scope']!=1){
           ajaxReturn (460001,'账号没有数据权限');
        }
        $isqx=isAuthority($user['role'],'maintain/data/database/index');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        return dbBackup::getDataList(@$dt['pages']);
    }
    // 操作数据库
    function operationDb($dt=[]){
        $user = isLogin();
        $uid=$user['uid'];
        if(@$user['role_scope']!=1){
           ajaxReturn (460001,'账号没有数据权限');
        }
        $isqx=isAuthority($user['role'],'maintain/data/database/editor');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        $rt=[
            "msg"=>"成功",
            "type"=>"info",
            "data"=>$dt
        ];
        if(@$dt['key']&&@$dt['data']){
            $key=$dt['key'];$data=$dt['data'];
            $yh=[];
            if($key=='youhua'){
                foreach($data as $k => $v){
                    if(intval($v['DATA_FREE'])>0){
                        $yh[$v['TABLE_NAME']]=dbBackup::optimize($v['TABLE_NAME']);
                    }
                }
                $rt=[
                    "msg"=>"优化成功",
                    "type"=>"success",
                    "data"=>$yh
                ]; 
            }
            if($key=='xiufu'){
                foreach($data as $k => $v){
                    if(intval($v['DATA_FREE'])>0){
                        $yh[$v['TABLE_NAME']]=dbBackup::repair($v['TABLE_NAME']);
                    }
                }
                $rt=[
                    "msg"=>"修复成功",
                    "type"=>"success",
                    "data"=>$yh
                ]; 
            }
            if($key=='beifen'){
                $rt=[
                    "msg"=>"备份成功",
                    "type"=>"success",
                    "data"=>$dt
                ]; 
            }
            $business_type='0';//2修改3删除
            $log_type="database";
            $log_title="数据表".$rt['msg'];
            $log_url='/admin/operationDb';
            $log_data['token']=$user['token'];
            $log_data['data']=$dt;
            $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
            $json_result=json_encode($rt,JSON_UNESCAPED_UNICODE);
            @$msg= '【'.$user['nickName'].'】'.$log_title.($rt?'成功':'失败');
            @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($rt?'0':'1'),$msg);
        }
        return $rt;
    }
    // 获取数据表表结构
    function getRead($tablename=""){
        if(!$tablename){
            return false;
        }
        return dbBackup::getRead($tablename);
    }
    
    //获取后台全局的配置
    function adminindex(){
        $wartermarkTime=Option::get('wartermarkTime');
        if($wartermarkTime=='1'){
            $wartermarkTime=" - ".date("Y-m-d");
        }else{
           $wartermarkTime=""; 
        }
        $wartermarkText=Option::get('wartermarkText').$wartermarkTime;
        $isWartermark=false;
        $user=isLogin(true);
        if($user['uid']){
            $isWartermark=Option::get('isWartermark')=='1'?true:false;
            if(Option::get('wartermarkType')=='2'){
                $wartermarkText=$user['uname'].$wartermarkTime;
            }
            if(Option::get('wartermarkType')=='3'){
                $wartermarkText=$user['nickName'].$wartermarkTime;
            }
            
        }
        // global $CACHE;
        $lockScreenBg=Option::get('lockScreenBg');
        $lockScreenBg=$lockScreenBg[rand(0,(count($lockScreenBg))-1)];
        return array(
            'dqTime'                    =>              date("Y"),
            'baseurl'                   =>              KINGMIN_URL,
            "siteUrl"                   =>              Option::get('siteUrl'),//网站地址
            'codeName'                  =>              Option::get('codeName'),//程序名字
            'codeDec'                   =>              Option::get('codeDec'),//程序说明
            'keywords'                  =>              Option::get('keywords'),//SEO
            'description'               =>              Option::get('description'),//SEO
            'codeLogo'                  =>              imgUrlpd(Option::get('codeLogo')),//程序LOGO
            'codeLogoMini'              =>              imgUrlpd(Option::get('codeLogoMini')),//程序LOGO
            'codeFavicon'               =>              imgUrlpd(Option::get('codeFavicon')),//favicon.ico
            'code_rightBtn'             =>              Option::get('code_rightBtn'),
            'code_Copyright'            =>              Option::get('code_Copyright'), //Option::get('code_name'),
            'isWartermark'              =>              $isWartermark, //Option::get('code_name'),
            'wartermarkText'            =>              $wartermarkText, //Option::get('code_name'),
            'lockScreenBg'              =>              $lockScreenBg, //Option::get('code_name'),
        );
    }
    // 获取附件页面前置
    function getPagesAttachment(){
        $typeList=[
                ["name"=>"图片","key"=>"1","selectType"=>Option::get('img_type')],
                ["name"=>"视频","key"=>"2","selectType"=>Option::get('video_type')],
                ["name"=>"音频","key"=>"3","selectType"=>Option::get('audio_type')],
                ["name"=>"其他","key"=>"4","selectType"=>Option::get('att_type')],
            ];
        $tbhdList=[
                ["paixu"=>"","align"=>"center","width"=>"100","type"=>"text","tb"=>false,"lxtype"=>["1","2","3","4"],"label"=>"ID","prop"=>"id","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"img","tb"=>false,"lxtype"=>["1","2","3","4"],"label"=>"缩略图","prop"=>"imgurl","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"text","tb"=>false,"lxtype"=>["1","2","3","4"],"label"=>"名称","prop"=>"fname","show"=>true],
                ["paixu"=>"1","align"=>"center","width"=>"","type"=>"text","tb"=>false,"lxtype"=>["1","2","3","4"],"label"=>"大小","prop"=>"fsize","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"tag","tb"=>false,"lxtype"=>["1","2","3","4"],"label"=>"存储位置","prop"=>"isuptp","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"tag","tb"=>false,"lxtype"=>["1","2","3","4"],"label"=>"上传类型","prop"=>"istype","show"=>false],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"list","tb"=>false,"lxtype"=>["1"],"label"=>"图片配置","prop"=>"remark","show"=>false],
                ["paixu"=>"","align"=>"center","width"=>"100","type"=>"user","tb"=>false,"lxtype"=>["1","2","3","4"],"label"=>"上传用户","prop"=>"createUser","show"=>true],
                ["paixu"=>"1","align"=>"center","width"=>"","type"=>"text","tb"=>false,"lxtype"=>["1","2","3","4"],"label"=>"上传时间","prop"=>"create_time","show"=>true],
            ];
        // $tbhdList=[
        //     ["colWidth"=>"","key"=>"id","title"=>"ID","type"=>"text","isCheck"=>true],    
        //     ["colWidth"=>"","key"=>"url","title"=>"缩略图","type"=>"image","isCheck"=>true],    
        //     ["colWidth"=>"","key"=>"fname","title"=>"名称","type"=>"text","isCheck"=>true],    
        //     ["colWidth"=>"","key"=>"fsize","title"=>"大小","type"=>"text","isCheck"=>true],    
        //     ["colWidth"=>"","key"=>"isuptp","title"=>"存储位置","type"=>"text","isCheck"=>true],    
        //     ["colWidth"=>"","key"=>"istype","title"=>"上传类型","type"=>"text","isCheck"=>true],    
        //     ["colWidth"=>"","key"=>"create_time","title"=>"上传时间","type"=>"text","isCheck"=>true],    
        // ];
        return array(
            'typeList'                  =>              $typeList,
            'tbhdList'                  =>              $tbhdList,
            'type'                      =>              "1",
            'msg'                       =>              "",
            'selectType'                =>              Option::get('img_type'),
            'domain'                    =>              imgUrlpd("/api/upload"),
        );
    }
    // 获取日志模块前置
    function getPagesLog($type="login"){
        $operatortypeList=[
            ["name"=>"平台类型","key"=>""],
            ["name"=>"管理后台","key"=>"admin"],
            ["name"=>"微信小程序","key"=>"wxapp"],
            ["name"=>"APP","key"=>"app"],
        ];
        if($type=="operation"){
            $tbhdList=[
                ["paixu"=>"","align"=>"center","width"=>"80","type"=>"tag","label"=>"业务类型","prop"=>"business_type","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"100","type"=>"text","label"=>"操作平台","prop"=>"operator_type","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"100","type"=>"link","label"=>"操作类型","prop"=>"log_type","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"80","type"=>"tag","label"=>"操作状态","prop"=>"status","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"100","type"=>"user","label"=>"操作用户","prop"=>"user","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"操作动作","prop"=>"log_title","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"操作路由","prop"=>"log_url","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"操作参数","prop"=>"log_data","show"=>false],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"link","label"=>"操作IP","prop"=>"log_ip","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"归属地","prop"=>"location","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"浏览器","prop"=>"log_browser","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"操作系统","prop"=>"log_os","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"返回参数","prop"=>"json_result","show"=>false],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"提示消息","prop"=>"log_msg","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"备注说明","prop"=>"remark","show"=>false],
                ["paixu"=>"","align"=>"center","width"=>"200","type"=>"text","label"=>"操作时间","prop"=>"create_time","show"=>true],
            ];
            
            $businesstypeList=[
                    ["name"=>"业务类型","key"=>""],
                    ["name"=>"其他","key"=>"0"],
                    ["name"=>"新增","key"=>"1"],
                    ["name"=>"修改","key"=>"2"],
                    ["name"=>"删除","key"=>"3"],
                ];
        }
        if($type=="login"){
            $tbhdList=[
                ["paixu"=>"","align"=>"center","width"=>"80","type"=>"tag","label"=>"登录平台","prop"=>"status","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"100","type"=>"user","label"=>"登录用户","prop"=>"user","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"100","type"=>"link","label"=>"登录账号","prop"=>"user_name","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"80","type"=>"tag","label"=>"登录状态","prop"=>"log_status","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"link","label"=>"操作IP","prop"=>"log_ip","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"归属地","prop"=>"location","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"浏览器","prop"=>"log_browser","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"操作系统","prop"=>"log_os","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"提示消息","prop"=>"log_msg","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"备注说明","prop"=>"remark","show"=>false],
                ["paixu"=>"","align"=>"center","width"=>"200","type"=>"text","label"=>"操作时间","prop"=>"create_time","show"=>true],
            ];
            $businesstypeList=[
                ["name"=>"登录状态","key"=>""],
                ["name"=>"登录成功","key"=>"1"],
                ["name"=>"账号错误","key"=>"2"],
                ["name"=>"账号密码","key"=>"3"],
                ["name"=>"账号异常","key"=>"5"],
            ];
        }
        if($type=="error"){
            $tbhdList=[
                ["paixu"=>"","align"=>"center","width"=>"100","type"=>"text","label"=>"操作平台","prop"=>"operator_type","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"80","type"=>"tag","label"=>"业务类型","prop"=>"error_type","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"错误参数","prop"=>"log_data","show"=>false],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"link","label"=>"操作IP","prop"=>"log_ip","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"归属地","prop"=>"location","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"浏览器","prop"=>"log_browser","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"操作系统","prop"=>"log_os","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"返回参数","prop"=>"json_result","show"=>false],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"提示消息","prop"=>"log_msg","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"备注说明","prop"=>"remark","show"=>false],
                ["paixu"=>"","align"=>"center","width"=>"200","type"=>"text","label"=>"操作时间","prop"=>"create_time","show"=>true],
            ];
            
            $businesstypeList=[
                ["name"=>"业务类型","key"=>""],
                ["name"=>"其他","key"=>"0"],
                ["name"=>"数据库","key"=>"1"],
            ];
        }
        return array(
            'tbhdList'                  =>              $tbhdList??[],
            'logtypeList'               =>              $logtypeList??[],
            'operatortypeList'          =>              $operatortypeList??[],
            'businesstypeList'          =>              $businesstypeList??[],
            'type'                      =>              $type,
        );
    }
    // 获取角色页面前置
    function getPagesRole(){
        $tbhdList=[
            ["editor"=>"1","paixu"=>"1","align"=>"center","width"=>"80","type"=>"text","label"=>"排序","prop"=>"order_num","show"=>true],
            ["editor"=>"","paixu"=>"","align"=>"center","width"=>"","type"=>"text","label"=>"角色名称","prop"=>"role_name","show"=>true],
            ["editor"=>"","paixu"=>"","align"=>"center","width"=>"","type"=>"link","label"=>"角色标识符","prop"=>"role_key","show"=>true],
            ["editor"=>"","paixu"=>"","align"=>"center","width"=>"150","type"=>"tag","label"=>"数据权限","prop"=>"data_scopeTag","show"=>true],
            ["editor"=>"","paixu"=>"","align"=>"center","width"=>"150","type"=>"tag","label"=>"角色状态","prop"=>"statusTag","show"=>true],
            ["editor"=>"","paixu"=>"","align"=>"center","width"=>"150","type"=>"user","label"=>"创建用户","prop"=>"createUser","show"=>true],
            ["editor"=>"","paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"备注说明","prop"=>"remark","show"=>false],
            ["editor"=>"","paixu"=>"1","align"=>"center","width"=>"200","type"=>"text","label"=>"创建时间","prop"=>"create_time","show"=>true],
            ["editor"=>"","paixu"=>"","align"=>"center","width"=>"150","type"=>"user","label"=>"修改用户","prop"=>"updateUser","show"=>false],
            ["editor"=>"","paixu"=>"1","align"=>"center","width"=>"200","type"=>"text","label"=>"修改时间","prop"=>"update_time","show"=>false],
        ];
        return array(
            'tbhdList'                  =>              $tbhdList??[],
        );
    }
    // 获取用户前置
    function getPagesMember($path='member'){
        if($path=="admin"){
            $tbhdList=[
                ["paixu"=>"1","align"=>"center","width"=>"80","type"=>"text","label"=>"UID","prop"=>"uid","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"100","imgWidth"=>"50","imgHeight"=>"50","type"=>"img","label"=>"头像","prop"=>"avatar","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"text","label"=>"登录账号","prop"=>"uname","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"text","label"=>"用户昵称","prop"=>"nickName","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"text","label"=>"手机号码","prop"=>"phone","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"设备","prop"=>"device","show"=>false],
                ["paixu"=>"","align"=>"center","width"=>"150","type"=>"tag","label"=>"性别","prop"=>"sex","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"邮箱","prop"=>"email","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"微信","prop"=>"wx","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"text","label"=>"QQ","prop"=>"qq","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"link","label"=>"管理权限","prop"=>"roleName","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"150","type"=>"tag","label"=>"用户状态","prop"=>"statusTag","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"link","label"=>"注册IP","prop"=>"register_ip","show"=>false],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"link","label"=>"最后登录IP","prop"=>"login_ip","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"最后登录时间","prop"=>"login_date","show"=>false],
                ["paixu"=>"1","align"=>"center","width"=>"","type"=>"text","label"=>"登录次数","prop"=>"login_num","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"备注说明","prop"=>"remark","show"=>false],
                ["paixu"=>"1","align"=>"center","width"=>"200","type"=>"text","label"=>"创建时间","prop"=>"create_time","show"=>true],
            ];
            $herder=[
                "status"=>[
                    ["key"=>"","title"=>"状态"],
                    ["key"=>"0","title"=>"正常"],
                    ["key"=>"1","title"=>"停用"],
                ],        
                "gender"=>[
                    ["key"=>"","title"=>"性别"],
                    ["key"=>"0","title"=>"男性"],
                    ["key"=>"1","title"=>"女性"],
                    ["key"=>"2","title"=>"未知"],
                ],
                "search"=>[
                    ["key"=>"uid","title"=>"UID"],
                    ["key"=>"uname","title"=>"用户名或昵称"],
                    ["key"=>"phone","title"=>"手机号码"],
                    ["key"=>"email","title"=>"邮箱"],
                    ["key"=>"qq","title"=>"QQ"],
                    ["key"=>"wx","title"=>"微信"],
                ],
                "role"=>[
                    ["key"=>"","title"=>"角色"],
                ],
            ];
            $pages['isAll']=true;
            $roleList=User_Model::getRoleList($pages);
            foreach($roleList['list'] as $v){
                if($v['role_key']!='ordinary')
                $herder['role'][]=["key"=>$v['role_key'],"title"=>$v['role_name']];
            }
        }
        if($path=="member"){
            $tbhdList=[
                ["paixu"=>"1","align"=>"center","width"=>"80","type"=>"text","label"=>"UID","prop"=>"uid","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"100","imgWidth"=>"50","imgHeight"=>"50","type"=>"img","label"=>"头像","prop"=>"avatar","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"text","label"=>"登录账号","prop"=>"uname","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"text","label"=>"用户昵称","prop"=>"nickName","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"text","label"=>"手机号码","prop"=>"phone","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"设备","prop"=>"device","show"=>false],
                ["paixu"=>"","align"=>"center","width"=>"150","type"=>"tag","label"=>"性别","prop"=>"sex","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"邮箱","prop"=>"email","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"微信","prop"=>"wx","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"text","label"=>"QQ","prop"=>"qq","show"=>true],
                // ["paixu"=>"","align"=>"center","width"=>"","type"=>"link","label"=>"管理权限","prop"=>"roleName","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"150","type"=>"tag","label"=>"用户状态","prop"=>"statusTag","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"link","label"=>"注册IP","prop"=>"register_ip","show"=>false],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"link","label"=>"最后登录IP","prop"=>"login_ip","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"最后登录时间","prop"=>"login_date","show"=>false],
                ["paixu"=>"1","align"=>"center","width"=>"","type"=>"text","label"=>"登录次数","prop"=>"login_num","show"=>true],
                ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"备注说明","prop"=>"remark","show"=>false],
                ["paixu"=>"1","align"=>"center","width"=>"200","type"=>"text","label"=>"创建时间","prop"=>"create_time","show"=>true],
            ];
            $herder=[
                "status"=>[
                    ["key"=>"","title"=>"状态"],
                    ["key"=>"0","title"=>"正常"],
                    ["key"=>"1","title"=>"停用"],
                ],        
                "gender"=>[
                    ["key"=>"","title"=>"性别"],
                    ["key"=>"0","title"=>"男性"],
                    ["key"=>"1","title"=>"女性"],
                    ["key"=>"2","title"=>"未知"],
                ],
                "search"=>[
                    ["key"=>"uid","title"=>"UID"],
                    ["key"=>"uname","title"=>"用户名或昵称"],
                    ["key"=>"phone","title"=>"手机号码"],
                    ["key"=>"email","title"=>"邮箱"],
                    ["key"=>"qq","title"=>"QQ"],
                    ["key"=>"wx","title"=>"微信"],
                ]
            ];
        }
       return array(
            'tbhdList'                  =>              $tbhdList??[],
            'heard'                    =>              $herder??[],
        );
    }
    // 获取数据库前置
    function getPagesDatabase(){
        $tbhdList=[
            ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"表名称","prop"=>"TABLE_NAME","show"=>true],
            ["paixu"=>"","align"=>"center","width"=>"","type"=>"data","label"=>"表备注","prop"=>"TABLE_COMMENT","show"=>true],
            ["paixu"=>"","align"=>"center","width"=>"","type"=>"text","label"=>"类型","prop"=>"ENGINE","show"=>true],
            ["paixu"=>"","align"=>"center","width"=>"150","type"=>"text","label"=>"大小","prop"=>"kb","show"=>true],
            ["paixu"=>"","align"=>"center","width"=>"150","type"=>"text","label"=>"行数","prop"=>"TABLE_ROWS","show"=>true],
            ["paixu"=>"","align"=>"center","width"=>"150","type"=>"text","label"=>"沉余","prop"=>"gain","show"=>true],
            ["paixu"=>"","align"=>"center","width"=>"150","type"=>"text","label"=>"更新时间","prop"=>"UPDATE_TIME","show"=>true],
        ];
        return array(
            'tbhdList'                  =>              $tbhdList??[],
        );
    }
    //获取后台登录前的配置
    function loginInfo(){
        // global $CACHE;
        $loginBg=Option::get('loginBg');
        $loginBg=$loginBg[rand(0,(count($loginBg))-1)];
        return array(
            'dqTime'                    =>              date("Y"),
            "siteUrl"                   =>              Option::get('siteUrl'),//网站地址
            'codeName'                  =>              Option::get('codeName'),//程序名字
            'codeDec'                   =>              Option::get('codeDec'),//程序说明
            'keywords'                  =>              Option::get('keywords'),//SEO
            'description'               =>              Option::get('description'),//SEO
            'codeLogo'                  =>              imgUrlpd(Option::get('codeLogo')),//程序LOGO
            'codeLogoMini'              =>              imgUrlpd(Option::get('codeLogoMini')),//程序LOGO
            'loginBg'                   =>              $loginBg,//登录背景
            'checkcode'                 =>              imgUrlpd('/api/admin/code/'.Option::get('codeType')),//登录验证码
            'isCode'                    =>              intval(Option::get('isCode')),//是否开启登录验证码
            'isSmsLogin'                =>              intval(Option::get('isSmsLogin')),//是否开启登录验证码
            // 'testList'=>getRequestFormType(),
            // 'test'=>$_SERVER,
        );
    }
   
    // 获取后台所有的菜单
    function getAllmenu(){
        $user=isLogin(false);
        global $CACHE;
        $menu = $CACHE->readCache('menus');
        $usermenu=[];
        if(@$user['uid']){
            foreach ($menu as $k=> $v ){
                if($user['role']==$k){
                    $usermenu=$v;
                }
            }
        }else{
            $usermenu=$menu['ordinary'];
        }
        if(count($usermenu)<=0){
            $usermenu=[
                [
                    "component"=>"home/index",
                    "id"=>"1",
                    "meta"=>[
                        "title"=> "首页",
                        "isLink"=> "", 
                        "isHide"=> false, 
                        "isKeepAlive"=> true, 
                        "isAffix"=> true,
                        "isIframe"=>false,
                        "icon"=>"iconfont icon-shouye",
                        "roleBtn"=>[],
                        "roles"=>[]
                    ],
                    "name"=>"home",
                    "path"=>"/home",
                    "redirect"=>"",
                ]
            ];
        }
        return $usermenu;
        
    }
    // 判断是否有子菜单
    function getAllrolemenu(){
        
        // $user=isLogin(true);
        // global $CACHE;
        // $menu = $CACHE->readCache('menus');
        // if(@$user['uid']){
        //     foreach ($menu as $k=> $v ){
        //         if($user['role']==$k){
        //             $usermenu=$v;
        //         }
        //     }
        // }else{
        //     $usermenu=$menu;
        // }
        $m=new Menu_Model();
        $usermenu=$m->getAllrolemenu();
        return $usermenu;
        
    }
    
    // 获取系统消息列表
    function getinFormList($dt=[]){
        $db = Database::getInstance();
        @$isAll=$dt['pages']['isAll'];
        $output = [
			'pages'=>[
			    'isAll'=>$isAll?true:false,
    			'recordCount' => 0,     //满足条件的总记录数
    		    'pageSize' => 10,        //每页大小，即每页最多可以显示的记录数量
    		    'pageCount' => 0,       //总页数
    		    'pno' => 1,          //当前数据所在页号
			 ],
			'list' => [] ,         //当前页中的数据
	    ];
        $wSql="";$TSql='';$isfym="";
        $user = getLoginUser();
        $uid=$user['uid'];
        $xt=0;
        $info=0;
        $info=intval($user['info']);
        
        $bySql="ORDER BY create_time DESC ";
        
        $pno = 1;$pgs = intval(Option::get('pagesSize'));
	    if(@$dt['pages']['pno']){
		  $pno = intval($dt['pages']['pno']);
		}
        if(@$dt['pages']['pageSize']){
		  $pgs = intval($dt['pages']['pageSize']);
		}
		
		if(@$dt['type']){
		    $wSql=" AND `notice_type`= '".$dt['type']."' ";
		    $TSql=" AND ( `user`='".$user['uid']."' OR `user`='all' ";
		    if($dt['type']=='1'){
		        if($user['role_scope']=='1'){
		            $TSql.=" OR `user`='gl' ";
		        }
		    }
		    $TSql.=" ) ";
		}else{
		    $TSql=" AND ( `user`='".$user['uid']."' OR `user`='all' ";
		    if($user['role_scope']=='1'){
		        $TSql.=" OR `user`='gl' ";
		    }
		    $TSql.=" ) ";
		}
		
		
		$output['pages']['pageSize']=$pgs;$output['pages']['pno']=$pno; 
		$totalSql = " SELECT COUNT(*) as total  FROM `" . DB_PREFIX . "sys_notice` WHERE  `isdel`='0' AND `status`='0' AND `user_type`='admin' $wSql $TSql ";
		$res = $db->fetch_array($db->query($totalSql));
		$output['pages']['recordCount'] = intval($res['total']);
		$total=intval($res['total']);
		if($total>$info){
    	    $xt=($total-$info);
    	}
		//计算总页数
		$output['pages']['pageCount'] = ceil($output['pages']['recordCount']/$output['pages']['pageSize']);
		//获取指定页中的数据
		$start = ($output['pages']['pno']-1)*$output['pages']['pageSize'];
		$count = $output['pages']['pageSize'];
		if(!$output['pages']['isAll']){
			$isfym="LIMIT $start,$count";
	    }
        
        $sql = "SELECT * FROM  `" . DB_PREFIX . "sys_notice`  WHERE  `isdel`='0' AND `status`='0' AND `user_type`='admin' $wSql $TSql $bySql $isfym ;";
        $logs = $db->query($sql);
        $data = array();
        foreach ($logs as $key => $v) {
            $v['time']=smartDate(strtotime($v['create_time']));
            $v['notice_content']=urldecode($v['notice_content']);
            $v['zaiyao']=extractHtmlData($v['notice_content'],38);
            $data[]=$v;
        }
        
        $output['list']=$data;
        // $output['sql']=$sql;
		$output['read']=false;
        if(@$dt['isread']){
            $db->query('UPDATE `'.DB_PREFIX."sys_member` SET info = '$total' WHERE uid='$uid'");
            $output['read']=true;
            $xt=0;
            userGenxin();
        }
        $output['xt']=$xt;
        return $output;
    }
    // 发布通知
    function addInForm($dt){
        $user = isLogin();
        // ajaxReturn(404,'参数为空',$dt);
        if(!is_array($dt)){ajaxReturn(404,'参数为空');}
        $uid=$user['uid'];
        if(@!$dt['user_type']){
            $dt['user_type']="admin";
        }
        $dt['create_by']=$user['uid'];
        $dt['update_by']=$user['uid'];
        // return $upStr;
        $db = Database::getInstance();
        $sql = addSqlConvert('sys_notice',$dt);
        //   return $sql;
        $query = $db->query($sql);
        $log_type="inform";
        $log_title="发布通知消息";
        $log_url='/admin/addInForm';
        $log_data['token']=$user['token'];
        $log_data['data']=$dt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($query,JSON_UNESCAPED_UNICODE);
       
        if ($query) {
            $msg='用户【'.$user['nickName'].'】'.$log_title.',成功';
            @$caozuorz=addOperationLog($uid,"1","1",$log_type,$log_title,$log_url,$log_data,$json_result,"0",$msg);
            return true;
        } else {
            $msg='用户【'.$user['nickName'].'】'.$log_title.',失败';
             @$caozuorz=addOperationLog($uid,"1","1",$log_type,$log_title,$log_url,$log_data,$json_result,"1",$msg);
            return false;
        }
    }
    // 获取用户信息
    function getUserList($dt=[]){
        $dt['data']['name']="uname";
        // return $dt;
        return User_Model::getUserList($dt['pages'],$dt['data']);
    }
    // 获取附件文件夹
    function getFileList($dt=[]){
        $db = Database::getInstance();
        @$isAll=$dt['pages']['isAll'];
        $output = [
			'pages'=>[
			    'isAll'=>$isAll?true:false,
    			'recordCount' => 0,     //满足条件的总记录数
    		    'pageSize' => 10,        //每页大小，即每页最多可以显示的记录数量
    		    'pageCount' => 0,       //总页数
    		    'pno' => 1,          //当前数据所在页号
			 ],
			'list' => [] ,         //当前页中的数据
	    ];
        $wSql="";$mSql='';$isfym="";
        $user = isLogin();
        $uid=$user['uid'];
        
        $bySql="ORDER BY `paixu` ASC,`create_time` DESC ";
        
        $pno = 1;$pgs = intval(Option::get('pagesSize'));
	    if(@$dt['pages']['pno']){
		  $pno = intval($dt['pages']['pno']);
		}
        if(@$dt['pages']['pageSize']){
		  $pgs = intval($dt['pages']['pageSize']);
		}
		
		if(@$dt['type']){
		    $wSql.=" AND `type`='".$dt['type']."' " ;
		}else{
		    return $output;
		}
		if(@$dt['my']){
		    $mSql=" AND `uid`='$uid' ";
		}else{
    		if(@$user['role_scope']=='1'){
    		    $mSql="";
    		}else{
    		    $mSql=" AND ( `uid`='$uid' OR uid='0' )";
    		}
		}
		if(@$dt['key']){
		    $wSql.=" AND `fileName` LIKE '%".$dt['key']."%' " ; 
		}
		
		$output['pages']['pageSize']=$pgs;$output['pages']['pno']=$pno; 
		$totalSql = " SELECT COUNT(*) as total  FROM `" . DB_PREFIX . "sys_upload_file` WHERE  `isdel`='0' $wSql $mSql ";
		$res = $db->fetch_array($db->query($totalSql));
		$output['pages']['recordCount'] = intval($res['total']);
		//计算总页数
		$output['pages']['pageCount'] = ceil($output['pages']['recordCount']/$output['pages']['pageSize']);
		//获取指定页中的数据
		$start = ($output['pages']['pno']-1)*$output['pages']['pageSize'];
		$count = $output['pages']['pageSize'];
		if(!$output['pages']['isAll']){
			$isfym="LIMIT $start,$count";
	    }
        
        $sql = "SELECT * FROM  `" . DB_PREFIX . "sys_upload_file`  WHERE  `isdel`='0' $wSql $mSql $bySql $isfym ;";
        $logs = $db->query($sql);
        $data=[];
        if($output['pages']['pno']==1&&@!$dt['key']){
           $totalSql = " SELECT COUNT(*) as total  FROM `" . DB_PREFIX . "sys_upload` WHERE  `isdel`='0' AND `fid`='0' $mSql "." AND `type`='".$dt['type']."' ";
    	   $res = $db->fetch_array($db->query($totalSql));
           $totalAllSql = " SELECT COUNT(*) as total  FROM `" . DB_PREFIX . "sys_upload` WHERE  `isdel`='0' $mSql "." AND `type`='".$dt['type']."' ";
    	   $all = $db->fetch_array($db->query($totalAllSql));
           $data =[
                [
                'id'=>'',
                'fileName'=>'全部',
                'total'=>intval($all['total']),
                ],
                [
                'id'=>'0',
                'fileName'=>'未分类',
                'total'=>intval($res['total']),
                ]
            ]; 
        }
        foreach ($logs as $key => $v) {
            $totalSql = " SELECT COUNT(*) as total  FROM `" . DB_PREFIX . "sys_upload` WHERE  `isdel`='0' AND `fid`='".$v['id']."' $mSql "." AND `type`='".$dt['type']."' ";
    	    $res = $db->fetch_array($db->query($totalSql));
            $nv=[
                'id'=>$v['id'],
                'fileName'=>$v['fileName'],
                'total'=>intval($res['total']),
                'uid'=>$v['uid'],
                'paixu'=>$v['paixu'],
                'remark'=>$v['remark'],
                'create_time'=>$v['create_time'],
                'update_time'=>$v['update_time'],
            ];
            array_push($data,$nv);
        }
        
        $output['list']=$data;
        $output['type']=$dt['type'];
        // $output['sql']=$sql;
        return $output;
    }
    // 新建文件夹
    function addFile($dt=[]){
        $user = isLogin();
        $uid=$user['uid'];
        @$fileName=$dt['fileName'];
        if (empty($fileName)) {
            ajaxReturn (404,'参数为空',$dt);
        }
        @$type=$dt['type'];
        if (empty($fileName)) {
            ajaxReturn (404,'参数为空',$dt);
        }
        $isqx=isAuthority($user['role'],'routine/attachment/add');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        if(!preg_match("/^[\x{4e00}-\x{9fa5}A-Za-z0-9_]{2,8}$/u",$fileName)){
            ajaxReturn (300,'格式不正确,只能输入2-8个字符');
        }
        $fileJyList=[
            "全部","admin","null"
            ];
        if(in_array($fileName,$fileJyList )){
            ajaxReturn (302,'文件夹名字有误,输入的名字不被允许');
        }
        $db = Database::getInstance();
        // $sql="SELECT * FROM `".DB_PREFIX."sys_upload_file` WHERE `fileName` = '$fileName' AND isdel='0' AND ( `uid`='$uid' OR `uid`='0' OR `uid`='' )";
        if ($fileData = $db->once_fetch_array("SELECT * FROM `".DB_PREFIX."sys_upload_file` WHERE `type`='$type' AND `fileName` = '$fileName' AND isdel='0' AND ( `uid`='$uid' OR `uid`='0' OR `uid`='' )")) {
            ajaxReturn (300,'文件夹名字重复');
        }
        $dt['uid']=$uid;
        $dt['update_by']=$uid;
        $sql = addSqlConvert('sys_upload_file',$dt);
        // return $sql;
        // return $user;
        $res=$db->query($sql);
        
        $log_type="file";
        $log_title="新增文件夹";
        $log_url='/admin/addFile';
        $log_data['token']=$user['token'];
        $log_data['data']=$dt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($res,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.'成功';
        @$caozuorz=addOperationLog($uid,"1","1",$log_type,$log_title,$log_url,$log_data,$json_result,($res?'0':'1'),$msg);
         
        return $res;
    }
    // 修改文件夹
    function upFile($dt=[]){
        $user = isLogin();
        $uid=$user['uid'];
        @$id=$dt['id'];
        if (empty($id)) {
            ajaxReturn (404,'参数为空',$dt);
        }
        $isqx=isAuthority($user['role'],'routine/attachment/editor');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        $dt['update_by']=$uid;
        $db = Database::getInstance();
    	if(@$dt['isdel']){
            $totalSql = " SELECT COUNT(*) as total  FROM `" . DB_PREFIX . "sys_upload` WHERE  `isdel`='0' AND `fid`='".$id."' ";
        	$res = $db->fetch_array($db->query($totalSql));
    	    if(intval($res['total'])>0){
    	        ajaxReturn (900000,'请删除文件夹下的附件,获取移走文件夹下的附件');
    	    }
    	}
        unset($dt['id']);
        $sql = upSqlConvert('sys_upload_file',$dt," `id`='$id' ");
        // return $sql;
        // return $user;
        $res=$db->query($sql);
        $business_type='2';//2修改3删除
        $log_type="file";
        $log_title="修改文件夹";
        if(@$dt['isdel']){
            $business_type='3';
            $log_title="删除文件夹";
        }
        $log_url='/admin/upFile';
        $log_data['token']=$user['token'];
        $log_data['data']=$dt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($res,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.'成功';
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($res?'0':'1'),$msg);
        return $res;
    }
    // 获取文件列表
    function getAccessoryList($dt=[]){
        $db = Database::getInstance();
        @$isAll=$dt['pages']['isAll'];
        $output = [
			'pages'=>[
			    'isAll'=>$isAll?true:false,
    			'recordCount' => 0,     //满足条件的总记录数
    		    'pageSize' => 10,        //每页大小，即每页最多可以显示的记录数量
    		    'pageCount' => 0,       //总页数
    		    'pno' => 1,          //当前数据所在页号
			 ],
			'list' => [] ,         //当前页中的数据
	    ];
        $wSql="";$mSql='';$isfym="";
        $user = isLogin();
        $uid=$user['uid'];
        
        $bySql="ORDER BY `id` DESC ";
        
        $pno = 1;$pgs = intval(Option::get('pagesSize'));
	    if(@$dt['pages']['pno']){
		  $pno = intval($dt['pages']['pno']);
		}
        if(@$dt['pages']['pageSize']){
		  $pgs = intval($dt['pages']['pageSize']);
		}
		
		if(@$dt['istype']){
		    $wSql.=" AND `istype`='".$dt['istype']."' " ;
		}
		if(@$dt['fileId']||@$dt['fileId']=='0'){
		    $wSql.=" AND `fid`='".$dt['fileId']."' " ;
		}
		if(@$dt['isuptp']){
		    $wSql.=" AND `isuptp`='".$dt['isuptp']."' " ;
		}
		if(@$dt['type']){
		    $wSql.=" AND `type`='".$dt['type']."' " ;
		}else{
		    return $output;
		}
		if(@$dt['my']){
		    $mSql=" AND `uid`='$uid' ";
		}else{
    		if(@$user['role_scope']=='1'){
    		    $mSql="";
    		}else{
    		    $mSql=" AND ( `uid`='$uid' OR uid='0' )";
    		}
		}
		if(@$dt['key']){
		    $wSql.=" AND `fname` LIKE '%".$dt['key']."%' " ; 
		}
		if(@$dt['orderBy']){
		    if($dt['orderBy']=="fsizeDesc"){
		        $bySql="ORDER BY `fsize` DESC ";
		    }
		    if($dt['orderBy']=="fsizeAsc"){
		        $bySql="ORDER BY `fsize` ASC ";
		    }
		    if($dt['orderBy']=="timeAsc"){
		        $bySql="ORDER BY `create_time` ASC ";
		    }
		    if($dt['orderBy']=="timeDesc"){
		        $bySql="ORDER BY `create_time` DESC ";
		    }
		}
		
		
		$output['pages']['pageSize']=$pgs;$output['pages']['pno']=$pno; 
		$totalSql = " SELECT COUNT(*) as total  FROM `" . DB_PREFIX . "sys_upload` WHERE  `isdel`='0' $wSql $mSql ";
		$res = $db->fetch_array($db->query($totalSql));
		$output['pages']['recordCount'] = intval($res['total']);
		//计算总页数
		$output['pages']['pageCount'] = ceil($output['pages']['recordCount']/$output['pages']['pageSize']);
		//获取指定页中的数据
		$start = ($output['pages']['pno']-1)*$output['pages']['pageSize'];
		$count = $output['pages']['pageSize'];
		if(!$output['pages']['isAll']){
			$isfym="LIMIT $start,$count";
	    }
        
        $sql = "SELECT * FROM  `" . DB_PREFIX . "sys_upload`  WHERE  `isdel`='0' $wSql $mSql $bySql $isfym ;";
        $logs = $db->query($sql);
        $data=[];
        foreach ($logs as $key => $v) {
            $v['remark']=json_decode($v['remark'],true);
            $v['fsize']=format_size(intval($v['fsize'])*1024);
            if($v['isuptp']=='1'){
                $tag=[
                    "type"=>"success",
                    "label"=>"本地服务器",
                ];
            }
            if($v['isuptp']=='2'){
                $tag=[
                    "type"=>"warning",
                    "label"=>"七牛云",
                ];
            }
            if($v['isuptp']=='3'){
                $tag=[
                    "type"=>"danger",
                    "label"=>"阿里云",
                ];
            }
            $v['isuptp']=$tag;
            if($v['istype']=='1'){
                $tag=[
                    "type"=>"info",
                    "label"=>"前端",
                ];
            }
            if($v['istype']=='2'){
                $tag=[
                    "type"=>"success",
                    "label"=>"后台",
                ];
            }
            $v['istype']=$tag;
            $v['imgurl']=imgurlpd($v['imgurl']);
            $v['yyurl']=imgUrlpd('/file/image/'.$v['id']."/".time());
            if($dt['type']=='1'){
                $v['imgurl']=imgurlpd($v['url']);
            }
            $createUser=[];
            if($v['uid']){
                if($v['uid']=='admin'){
                    $createUser=[
                        "uid"=>"admin",
                        "uname"=>"系统添加",
                    ];
                }else{
                   $createUser=User_Model::getMemberDetail($v['uid']); 
                }
            }
            $v['createUser']=$createUser;
            $data[]=$v;
        }
        
        $output['list']=$data;
        $output['type']=$dt['type'];
        // $output['sql']=$sql;
        return $output;
    }
    // 获取附件详情
    function getAccessoryDetail($id){
        $db = Database::getInstance();
        
        $sql = "SELECT * FROM `" . DB_PREFIX . "sys_upload` WHERE `id`='$id' ;";
        $logs = $db->query($sql);
        
        $data = array();
        $login= new LoginAuth();
        foreach ($logs as $key => $v) {
            @$v['remark']=json_decode($v['remark'],true);
            $data=$v;
        }
        
        return $data;
    }
    // 修改附件
    function upAccessory($dt=[]){
        $user = isLogin();
        $uid=$user['uid'];
        @$id=$dt['id'];
        if (empty($id)) {
            ajaxReturn (404,'参数为空',$dt);
        }
        $isqx=isAuthority($user['role'],'routine/attachment/editor');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        $dt['update_by']=$uid;
        unset($dt['id']);
        $sql = upSqlConvert('sys_upload',$dt," `id`='$id' ");
        // return $sql;
        // return $user;
        $db = Database::getInstance();
        $res=$db->query($sql);
        $business_type='2';//2修改3删除
        $log_type="accessory";
        $log_title="修改附件";
        if(@$dt['isdel']){
            $business_type='3';
            $log_title="删除附件";
        }
        $log_url='/admin/upAccessory';
        $log_data['token']=$user['token'];
        $log_data['data']=$dt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($res,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.'成功';
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($res?'0':'1'),$msg);
        return $res;
    }
    // 移动附件文件夹
    function moveAccessory($dt){
        $user = isLogin();
        $uid=$user['uid'];
        @$id=$dt['fileId'];
        if ($id||$id=='0') {
        }else{
            ajaxReturn (404,'参数为空',$dt);
        }
        @$list=$dt['id'];
        if(!is_array($list)){
            ajaxReturn (404,'参数为空',is_array($list));
        }
        $isqx=isAuthority($user['role'],'routine/attachment/editor');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        $wSql=" ";
        foreach ($list as $k => $v){
            $wSql.=" `id`='".$v['id']."' OR";
        }
        if(substr($wSql,-2)=='OR'){
            $wSql=substr($wSql,0,-2);
        }
        $newdt['update_by']=$uid;
        $newdt['fid']=$id;
        $sql = upSqlConvert('sys_upload',$newdt,$wSql);
        // return $sql;
        // return $user;
        $db = Database::getInstance();
        $res=$db->query($sql);
        $business_type='2';//2修改3删除
        $log_type="accessory";
        $log_title="移动附件";
        $log_url='/admin/moveAccessory';
        $log_data['token']=$user['token'];
        $log_data['data']=$dt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($res,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.'成功';
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($res?'0':'1'),$msg);
        return $res;
    }
    // 删除附件
    function delAccessory($dt){
        $user = isLogin();
        $uid=$user['uid'];
        if(!is_array($dt)){
            ajaxReturn (404,'参数为空',is_array($list));
        }
        $wSql=" ";
        foreach ($dt as $k => $v){
            $wSql.=" `id`='".$v['id']."' OR";
            deleteAccessory($v['id'],$user);
        }
        if(substr($wSql,-2)=='OR'){
            $wSql=substr($wSql,0,-2);
        }
        $newdt['update_by']=$uid;
        $newdt['isdel']=1;
        $sql = upSqlConvert('sys_upload',$newdt,$wSql);
        // return $sql;
        // return $user;
        $db = Database::getInstance();
        $res=$db->query($sql);
        $business_type='3';//2修改3删除
        $log_type="accessory";
        $log_title="删除附件";
        $log_url='/admin/delAccessory';
        $log_data['token']=$user['token'];
        $log_data['data']=$dt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($res,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.'成功';
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($res?'0':'1'),$msg);
        return $res;
    }
    function deleteAccessory($id,$user){
        if($id){
            $data=getAccessoryDetail($id);
            if($data['uid']!=$user['uid']){
                if($user['role_scope']!=1){
                    ajaxReturn (460001,'账号没有数据权限,无法删除此附件');
                }
            }
            $isqx=isAuthority($user['role'],'routine/attachment/del');
            if(@!$isqx){
               ajaxReturn (460000,'账号没有菜单权限');
            }
            $cache = new MyCache();
            $path=PASH_ROOT."/runtime/deleteLog/";
            $cache->dir =$path;//"../../../content/mycache/newadmin/";
            $cache->cacheFile ="accessory.json";
            $output["path"]=$data['ysurl'];$output["data"]=$data;
            if($data['isuptp']=='1'){
                $pic=PASH_ROOT.$data['ysurl'];
                if(file_exists($pic)){
                    $res = unlink($pic);
                    if($res){
    					$output["code"]=200;$output["msg"]='删除成功';
    		            $cache->setCache('SUCCESS',$output,0);
                    }else{
                        $output["code"]=1003;$output["msg"]='操作失误导致图片或文件无法删除';
    		            $cache->setCache('ERROR',$output,0);
                    }
                }else{
                    $output["code"]=1003;$output["msg"]='无法找到文件或者已经删除'.$pic;
    		        $cache->setCache('ERROR',$output,0);
                }
            }else if($data['isuptp']=='2'){
                $pic=substr($data['ysurl'],1);
                $sctp=deleteOldQiniu($pic);
                $output["code"]=200;$output["msg"]='删除成功';$output['qiniudata']=$sctp;
                $cache->setCache('SUCCESS',$output,0);
            }
        }
    }
    /**
     *
     * 七牛删除图片
     *
     */
    function deleteOldQiniu($filenames) {
        $qiniuyun=json_decode(Option::get('qiniuyun'),true);
        if(!$qiniuyun){
            return false;
        }else {
             @$accessKey=$qiniuyun['accesskey'];
             @$secretKey=$qiniuyun['secretkey'];
             @$bucket=$qiniuyun['bucket'];
             @$url=$qiniuyun['url'];
        }
        $auth = new Qiniu\Auth($accessKey, $secretKey);
        $config = new Qiniu\Config();
        $bucketManager = new Qiniu\Storage\BucketManager($auth, $config);
        //删除图片的名称
        $key = $filenames;
        $err = $bucketManager->delete($bucket, $key);
        if ($err) {
            return $err;
        }else {
            return true;
        }
    }
    // 获取日志
    function getOperationLog($dt){
        @$pages=$dt['pages'];
        @$data=$dt['data'];
        $user = isLogin();
        if($user){
            if($user['role_scope']==2){
               $data['uid']= $user['uid'];
            }
        }
        
        $log=new Log_Model();
        return $log->getOperationLog($pages,$data);
    }
    // 获取登录日志
    function getLoginLog($dt){
        @$pages=$dt['pages'];
        @$data=$dt['data'];
        $user = isLogin();
        if($user){
            if($user['role_scope']==2){
               $data['uid']= $user['uid'];
            }
        }
        
        $log=new Log_Model();
        return $log->getLoginLog($pages,$data);
    }
    // 获取错误日志
    function getErrorLog($dt){
        @$pages=$dt['pages'];
        @$data=$dt['data'];
        $user = isLogin();
        if($user){
            if($user['role_scope']==2){
               $data['uid']= $user['uid'];
            }
        }
        
        $log=new Log_Model();
        return $log->getErrorLog($pages,$data);
    }
    // 获取在线用户列表
    function getUserOnLineList($dt=[]){
        //  $user = isLogin();
         if(@$user){
            if($user['role_scope']!=1){
               ajaxReturn (450001,'账号没有数据权限',$user);
            }
        }
        if(!RedisService::op()){
            RedisService::init(3);
        }
        @$isAll=$dt['pages']['isAll'];
        $output = [
			'pages'=>[
			    'isAll'=>$isAll?true:false,
    			'recordCount' => 0,     //满足条件的总记录数
    		    'pageSize' => 10,        //每页大小，即每页最多可以显示的记录数量
    		    'pageCount' => 0,       //总页数
    		    'pno' => 1,          //当前数据所在页号
			 ],
			'list' => [] ,         //当前页中的数据
	    ];
	    $pno = 1;$pgs = intval(Option::get('pagesSize'));
	    if(@$dt['pages']['pno']){
		  $pno = intval($dt['pages']['pno']);
		}
        if(@$dt['pages']['pageSize']){
		  $pgs = intval($dt['pages']['pageSize']);
		}
		$output['pages']['pageSize']=$pgs;$output['pages']['pno']=$pno; 
		
		$output['pages']['recordCount'] = intval(RedisService::onLineNumber("user_*"));
		//计算总页数
		$output['pages']['pageCount'] = ceil($output['pages']['recordCount']/$output['pages']['pageSize']);
		//获取指定页中的数据
		$start = ($output['pages']['pno']-1)*$output['pages']['pageSize'];
		$count = $output['pages']['pageSize'];
		
        if(@$dt['count']){
            return $output['pages']['recordCount'];
        }
        
        if($output['pages']['recordCount']>0){
            $keyList=RedisService::onLineList("user_*");
            $userList=[];
            for($i=$start;$i<$count||$i<$output['pages']['recordCount'];$i++){
                if(@$keyList[$i]){
                    RedisService::setToken($keyList[$i]);
                    $user=RedisService::getUser();
                    $userList[]=$user;
                }
            }
            $output["list"]=$userList;
        }else{
            $output["list"]=[];
        }
        return $output;
    }
    
    // 获取用户权限列表
    function getRoleList($dt){
        @$pages=$dt['pages'];
        @$data=$dt['data'];
        $user = isLogin();
        if($user){
            if($user['role_scope']==2){
              ajaxReturn(401,"权限不够",$user);
            }
        }
        return User_Model::getRoleList($pages,$data);
    }
    // 获取树形菜单列表
    
    function getMenuList(){
        $user = isLogin();
        if($user){
            if($user['role_scope']==2){
              ajaxReturn(401,"权限不够",$user);
            }
        }
        return User_Model::getMenuList();
    }
    // 修改角色信息
    function upRoleDetail($dt=[]){
        $user = isLogin();
        $uid=$user['uid'];
        if(@$user['role_scope']!=1){
           ajaxReturn (460001,'账号没有数据权限');
        }
        if(@$dt['isdel']){
            $isqx=isAuthority($user['role'],'routine/super/role/del');
        }else{
            $isqx=isAuthority($user['role'],'routine/super/role/editor');
        }
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        $dt['update_by']=$uid;
        if(@$dt['delList']){
            return delAllRole($dt,$user);
        }
        @$id=$dt['role_id'];
        if (empty($id)) {
            ajaxReturn (404,'参数为空',$dt);
        }
        
        unset($dt['role_id']);
        $roleDateil=User_Model::getRoleDetail($id);
        // return $roleDateil;
        // uploadRoleDetail
        $isdt=isModification($dt,$roleDateil);
        $isdt['id']=$id;
        if($roleDateil['role_key']=='admin'){
            if($user['role']!='admin'){
                ajaxReturn (460000,'账号没有最高权限修改创始人角色');
            }
        }
        if(@$dt['isdel']){
            if($roleDateil['create_by']=='admin'){
                ajaxReturn (301,'不能删除系统创建的角色');
            }
        }
        $dt=$isdt['newData'];
        // ajaxReturn(201,"数据没有修改,和新数据和原始数据一样",$dt);
        $up=User_Model::uploadRoleDetail($dt,$id);
        
        // return $user;
        $business_type='2';//2修改3删除
        $log_type="role";
        $log_title="修改角色[".$roleDateil['role_name']."]信息";
        if(@$dt['isdel']){
            $business_type='3';
            $log_title="删除角色[".$roleDateil['role_name']."]信息";
        }
        $log_url='/admin/upRoleDetail';
        $log_data['token']=$user['token'];
        $log_data['data']=$isdt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($up,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($up?'成功':'失败');
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($up?'0':'1'),$msg);
        
        return $up;
    }
    // 批量删除角色
    function delAllRole($dt=false,$user){
        if(!$dt['delList']){
            return false;
        }
         $uid=$user['uid'];
        // 角色名字
        $list=$dt['delList'];
        unset($dt['delList']);
        $data=[];
        $xtcj="";
        foreach ($list as $k => $v){
            $roleDateil=User_Model::getRoleDetail($v);
            $data[]=[
                    "role_key"=>$roleDateil['role_key'],
                    "role_name"=>$roleDateil['role_name'],
                    "role_id"=>$v,
                ];
            if($roleDateil['create_by']!='admin'){
                $up=User_Model::uploadRoleDetail($dt,$v);
            }else{
                $xtcj.="[".$roleDateil['role_name']."]";
            }
        }
        $business_type='3';//2修改3删除
        $log_type="role";
        $log_title="批量删除角色[".$data[0]['role_name']."...]信息";
        $log_url='/admin/delAllRole';
        $log_data['token']=$user['token'];
        $log_data['data']=$data;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($up,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($up?'成功；'.($xtcj?"除系统创建的角色$xtcj外":""):'失败');
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($up?'0':'1'),$msg);
        
        return $up;
    }
    // 新增角色
    function addRoleDetail($dt){
        unset($dt['defaultKey']);
        unset($dt['role_id']);
        $user = isLogin();
        $uid=$user['uid'];
        if(@$user['role_scope']!=1){
           ajaxReturn (460001,'账号没有数据权限');
        }
        $isqx=isAuthority($user['role'],'routine/super/role/add');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        $roleKey=User_Model::getRoleDetailKey(@$dt['role_key'])??true;
        if($roleKey){
            ajaxReturn (300,'已经有重复的角色标识'.$dt['role_key'].'了',$dt);
        }
        $dt['create_by']=$uid;
        $dt['update_by']=$uid;
        $up=User_Model::addRoleDetail($dt);
        
        // return $user;
        $business_type='1';//2修改3删除
        $log_type="role";
        $log_title="新增角色[".$dt['role_name']."]信息";
        
        $log_url='/admin/addRoleDetail';
        $log_data['token']=$user['token'];
        $log_data['data']=$dt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($up,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($up?'成功':'失败');
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($up?'0':'1'),$msg);
        
        return $up;
    }
    
    // 获取管理员列表
    
    function getAdminList($dt=[]){
        $pages="";
        $data="";
        if(@$dt['pages']){
            $pages=$dt['pages'];
        }
        if(@$dt['data']){
            $data=$dt['data'];
        }
        
        $user = isLogin();
        $uid=$user['uid'];
        if(@$user['role_scope']!=1){
           ajaxReturn (460001,'账号没有数据权限');
        }
        $isqx=isAuthority($user['role'],'routine/super/admin/index');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        
        $list=LoginAuth::getAdminList($pages,$data,$user['uname']);
        
        return $list;
    }
    function upAdminDetail($dt){
        if(!is_array($dt)){
            ajaxReturn (404,'参数为空',$dt);
        }
        $user = isLogin();
        $logdt=$dt;
        @$id=$dt['uid'];
        unset($dt['uid']);
        if(@$dt['delList']){
            return delAllAdmin($dt,$user);
        }
        if(empty($id)){
            ajaxReturn (404,'参数为空',$dt);
        }
        $userDateil=User_Model::getMemberDetail($id);
        $uid=$user['uid'];
        if(@$user['role_scope']!=1){
           ajaxReturn (460001,'账号没有数据权限');
        }
        if(@$dt['isdel']){
            $isqx=isAuthority($user['role'],'routine/super/admin/del');
            if($userDateil['create_by']=='admin'){
                ajaxReturn (301,'不能删除系统创建的用户');
            }
        }elseif (@$dt['type']=='add') {
            $isqx=isAuthority($user['role'],'routine/super/admin/add');
        }else{
            $isqx=isAuthority($user['role'],'routine/super/admin/editor');
            // return $userDateil;
            if($userDateil['uname']=="kingmin"){
                if($user['uname']!="kingmin"){
                    ajaxReturn (301,'不能修改系统创建的用户');
                }
            }
            $isdt=isModification($dt,$userDateil);
            $dt=$isdt['newData'];
            $isdt['id']=$id;
            $logdt=$isdt;
        }
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        $memberKey=User_Model::getMemBerKey(@$dt['phone'],'phone')??true;
        if($memberKey){
            ajaxReturn (205,'手机号码已经存在了，请先解绑,或者更换其他号码');
        }
        $memberKey=User_Model::getMemBerKey(@$dt['email'],'email')??true;
        if($memberKey){
            ajaxReturn (205,'邮箱已经存在了,请换一个');
        }
        if(@$dt['phone']){
            if(!is_mobile(@$dt['phone'])){
                ajaxReturn (205,'手机号码格式不正确，请检查后提交',$dt);
            }
        }
        if(@$dt['email']){
            if(!checkMail(@$dt['email'])){
                ajaxReturn (205,'邮箱格式不正确,请换一个');
            }
        }
        $dt['update_by']=$uid;
        if(@$dt['password']){
            if(!is_password(@$dt['password'])){
                ajaxReturn (205,'密码强度不够,请换一个,密码必须由字母、数字组成,长度8-18');
            }
            $PHPASS = new PasswordHash(8, true);
            $password=$PHPASS->HashPassword($dt['password']);
            $dt['password']=$password;
        }else{
            unset($dt['password']);
        }
        unset($dt['type']);
        $up=User_Model::uploadMemberDetail($dt,$id);
        $business_type='2';//2修改3删除
        $log_type="admin";
        $log_title="修改管理员[".$userDateil['nickName']."]信息";
        if(@$dt['isdel']){
            $business_type='3';
            $log_title="删除管理员[".$userDateil['nickName']."]信息";
        }
        $log_url='/admin/upAdminDetail';
        $log_data['token']=$user['token'];
        $log_data['data']=$logdt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($up,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($up?'成功':'失败');
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($up?'0':'1'),$msg);
        
        return $up;
    }
        // 批量删除管理员
    function delAllAdmin($dt=false,$user){
        if(!$dt['delList']){
            return false;
        }
         $uid=$user['uid'];
        // 角色名字
        $list=$dt['delList'];
        unset($dt['delList']);
        $data=[];
        $xtcj="";
        foreach ($list as $k => $v){
            $userDateil=User_Model::getMemberDetail($v);
            $data[]=[
                    "nickName"=>$userDateil['nickName'],
                    "uname"=>$userDateil['uname'],
                    "uid"=>$v,
                ];
            $dt['isdel']=1;
            $dt['update_by']=$uid;
            $up=false;
            if($userDateil['create_by']!='admin'){
                $up=User_Model::uploadMemberDetail($dt,$v);
            }else{
                $xtcj.="[".$userDateil['nickName']."]";
            }
        }
        $business_type='3';//2修改3删除
        $log_type="admin";
        $log_title="批量删除管理员[".$data[0]['nickName']."...]信息";
        $log_url='/admin/delAllAdmin';
        $log_data['token']=$user['token'];
        $log_data['data']=$data;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($up,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($up?'成功；'.($xtcj?"除系统创建的用户$xtcj外":""):'失败');
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($up?'0':'1'),$msg);
        if($xtcj){
            if($up){
                ajaxReturn(200,"删除成功;除系统创建的用户$xtcj外",$xtcj);
            }else{
                ajaxReturn(201,"不能系统创建的用户$xtcj",$xtcj); 
            }
        }
        return $up;
    }
    
    // 获取用户列表
    
    function getMemberList($dt=[]){
        $pages="";
        $data="";
        if(@$dt['pages']){
            $pages=$dt['pages'];
        }
        if(@$dt['data']){
            $data=$dt['data'];
        }
        
        $user = isLogin();
        $uid=$user['uid'];
        
        $isqx=isAuthority($user['role'],'routine/super/admin/index');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        
        $list=User_Model::getMemberList($pages,$data,$user['uname']);
        
        return $list;
    }
    
    // 修改用户信息
    function upMemberDetail($dt){
        if(!is_array($dt)){
            ajaxReturn (404,'参数为空',$dt);
        }
        $user = isLogin();
        $logdt=$dt;
        @$id=$dt['uid'];
        unset($dt['uid']);
        if(@$dt['delList']){
            return delAllMember($dt,$user);
        }
        if(empty($id)){
            ajaxReturn (404,'参数为空',$dt);
        }
        $userDateil=User_Model::getMemberDetail($id);
        $uid=$user['uid'];
        if(@$user['role_scope']!=1){
           ajaxReturn (460001,'账号没有数据权限');
        }
        if(@$dt['isdel']){
            $isqx=isAuthority($user['role'],'member/user/del');
            if($userDateil['create_by']=='admin'){
                ajaxReturn (301,'不能删除系统创建的用户');
            }
        }else{
            $isqx=isAuthority($user['role'],'member/user/editor');
            // return $userDateil;
            if($userDateil['uname']=="kingmin"){
                if($user['uname']!="kingmin"){
                    ajaxReturn (301,'不能修改系统创建的用户');
                }
            }
            $isdt=isModification($dt,$userDateil);
            $dt=$isdt['newData'];
            $isdt['id']=$id;
            $logdt=$isdt;
        }
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        if(@$dt['phone']){
            $memberKey=User_Model::getMemBerKey(@$dt['phone'],'phone')??true;
            if($memberKey){
                ajaxReturn (205,'手机号码已经存在了，请先解绑,或者更换其他号码');
            }
            if(!is_mobile(@$dt['phone'])){
                ajaxReturn (205,'手机号码格式不正确，请检查后提交',$dt);
            }
        }
        if(@$dt['email']){
            $memberKey=User_Model::getMemBerKey(@$dt['email'],'email')??true;
            if($memberKey){
                ajaxReturn (205,'邮箱已经存在了,请换一个');
            }
            if(!checkMail(@$dt['email'])){
                ajaxReturn (205,'邮箱格式不正确,请换一个');
            }
        }
        $dt['update_by']=$uid;
        if(@$dt['password']){
            if(!is_password(@$dt['password'])){
                ajaxReturn (205,'密码强度不够,请换一个,密码必须由字母、数字组成,长度8-18');
            }
            $PHPASS = new PasswordHash(8, true);
            $password=$PHPASS->HashPassword($dt['password']);
            $dt['password']=$password;
        }else{
            unset($dt['password']);
        }
        unset($dt['type']);
        $up=User_Model::uploadMemberDetail($dt,$id);
        $business_type='2';//2修改3删除
        $log_type="member";
        $log_title="修改用户[".$userDateil['nickName']."]信息";
        if(@$dt['isdel']){
            $business_type='3';
            $log_title="删除用户[".$userDateil['nickName']."]信息";
        }
        $log_url='/admin/upMemberDetail';
        $log_data['token']=$user['token'];
        $log_data['data']=$logdt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($up,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($up?'成功':'失败');
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($up?'0':'1'),$msg);
        
        return $up;
    }
    
    // 批量删除用户
    function delAllMember($dt,$user){
        if(!$dt['delList']){
            return false;
        }
         $uid=$user['uid'];
         
        $list=$dt['delList'];
        unset($dt['delList']);
        $data=[];
        $xtcj="";
        foreach ($list as $k => $v){
            $userDateil=User_Model::getMemberDetail($v);
            $data[]=[
                    "nickName"=>$userDateil['nickName'],
                    "uname"=>$userDateil['uname'],
                    "uid"=>$v,
                ];
            $dt['isdel']=1;
            $dt['update_by']=$uid;
            $up=false;
            if($userDateil['create_by']!='admin'){
                $up=User_Model::uploadMemberDetail($dt,$v);
            }else{
                $xtcj.="[".$userDateil['nickName']."]";
            }
        }
        $business_type='3';//2修改3删除
        $log_type="member";
        $log_title="批量删除管理员[".$data[0]['nickName']."...]信息";
        $log_url='/admin/delAllMember';
        $log_data['token']=$user['token'];
        $log_data['data']=$data;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($up,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($up?'成功；'.($xtcj?"除系统创建的用户$xtcj外":""):'失败');
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($up?'0':'1'),$msg);
        if($xtcj){
            if($up){
                ajaxReturn(200,"删除成功;除系统创建的用户$xtcj外",$xtcj);
            }else{
                ajaxReturn(201,"不能系统创建的用户$xtcj",$xtcj); 
            }
        }
        return $up;
    }
    
    // 新增用户信息
    function addMemberDetail($dt){
        if(!is_array($dt)){
            ajaxReturn (404,'参数为空',$dt);
        }
        $user = isLogin();
        
        unset($dt['uid']);
        
        $isqx=isAuthority($user['role'],'member/user/add');
        
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        
        $memberKey=User_Model::getMemBerKey(@$dt['uname'],'uname')??true;
        if($memberKey){
            ajaxReturn (205,'用户名已经存在了,请换一个');
        }
        $memberKey=User_Model::getMemBerKey(@$dt['phone'],'phone')??true;
        if($memberKey){
            ajaxReturn (205,'手机号码已经存在了，请先解绑,或者更换其他号码');
        }
        $memberKey=User_Model::getMemBerKey(@$dt['email'],'email')??true;
        if($memberKey){
            ajaxReturn (205,'邮箱已经存在了,请换一个');
        }
        
        if(!is_uname(@$dt['uname'])){
            ajaxReturn (205,'用户名格式不正确,请换一个');
        }
        if(!is_mobile(@$dt['phone'])){
            ajaxReturn (205,'手机号码格式不正确，请检查后提交');
        }
        if(!checkMail(@$dt['email'])){
            ajaxReturn (205,'邮箱格式不正确,请换一个');
        }
        
        if(@$dt['password']){
            if(!is_password(@$dt['password'])){
                ajaxReturn (205,'密码强度不够,请换一个,密码必须由字母、数字组成,长度8-18');
            }
            $PHPASS = new PasswordHash(8, true);
            $password=$PHPASS->HashPassword($dt['password']);
            $dt['password']=$password;
        }else{
            ajaxReturn (205,'密码不能为空');
        }
        $dt['update_by']=$uid;
        $dt['create_by']=$uid;
        // return $dt;
        $up=User_Model::addMemberDetail($dt);
        $business_type='1';//2修改3删除
        $log_type="member";
        $log_title="新增用户[".$dt['nickName']."]信息";
        
        $log_url='/admin/addMemberDetail';
        $log_data['token']=$user['token'];
        $log_data['data']=$dt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($up,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($up?'成功':'失败');
        @$caozuorz=addOperationLog($user['uid'],$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($up?'0':'1'),$msg);
        
        return $up;
    }
    
    // 获取个人资料
    function getPersonalData(){
        $user = isLogin();
        $uid=$user['uid'];
        
        $isqx=isAuthority($user['role'],'routine/adminInfo/index');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        $userDateil=User_Model::getMemberDetail($uid);
        return $userDateil;
    }
    
    // 修改个人资料
    function upPersonalData($dt){
        $user = isLogin();
        $uid=$user['uid'];
        $userData=false;
        $isqx=isAuthority($user['role'],'routine/adminInfo/editor');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        if(@$dt['password']){
            if(@!$dt['oldPassword']){
                ajaxReturn(404,'请输入原密码');
            }
            if($dt['password']!=$dt['newPassword']){
                ajaxReturn(300,'两次输入的密码不一样');
            }
            if(!is_password(@$dt['password'])){
                ajaxReturn (205,'密码强度不够,请换一个,密码必须由字母、数字组成,长度8-18');
            }
            $lg =LoginAuth::checkUser($user['uname'],$dt['oldPassword'])??-2;
            // return $user;
            if($lg===-2){
                ajaxReturn (102,'原密码错误');
            }elseif($lg===-4){
                ajaxReturn (103,'账号被封禁');
            }else{
                $PHPASS = new PasswordHash(8, true);
                $userData['password'] = $PHPASS->HashPassword($dt['password']); 
            }
            if($dt['password']==$dt['oldPassword']){
                ajaxReturn(300,'新密码不能和旧密码一样');
            }
            $log_title="修改自己的密码";
        }else{
            if(@$dt['phone']){
                $memberKey=User_Model::getMemBerKey(@$dt['phone'],'phone')??true;
                if($memberKey){
                    ajaxReturn (205,'手机号码已经存在了，请先解绑,或者更换其他号码');
                }
                if(!is_mobile(@$dt['phone'])){
                    ajaxReturn (205,'手机号码格式不正确，请检查后提交',$dt);
                }
            }
            if(@$dt['email']){
                $memberKey=User_Model::getMemBerKey(@$dt['email'],'email')??true;
                if($memberKey){
                    ajaxReturn (205,'邮箱已经存在了,请换一个');
                }
                if(!checkMail(@$dt['email'])){
                    ajaxReturn (205,'邮箱格式不正确,请换一个');
                }
            }
            $userDateil=User_Model::getMemberDetail($uid);
            $isdt=isModification($dt,$userDateil);
            $userData=$isdt['newData'];
            $dt=$isdt;
            $log_title="修改个人资料";
        }
        $up=User_Model::uploadMemberDetail($userData,$uid);
        
        $business_type='2';//2修改3删除
        $log_type="member";
        
        $log_url='/admin/upPersonalData';
        $log_data['token']=$user['token'];
        $log_data['data']=$dt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($up,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($up?'成功':'失败');
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($up?'0':'1'),$msg);
        
        return $up;
    }
    // 获取系统配置分类
    function getConfigTab($set=false){
        $user = isLogin();
        $uid=$user['uid'];
        
        if($set){
            $set=true;
            $isqx=isAuthority($user['role'],'routine/set/index');
            if(@!$isqx){
               ajaxReturn (460000,'账号没有菜单权限');
            }
        }else{
            $set=false;
            $isqx=isAuthority($user['role'],'maintain/exploit/configtab/index');
            if(@!$isqx){
               ajaxReturn (460000,'账号没有菜单权限');
            }
        }
        $config=config_model::getConfigTabList($set);
        
        return $config;
    }
    // 获取系统分类信息
    function getConfigData($id=''){
        $user = isLogin();
        $uid=$user['uid'];
        
        $isqx=isAuthority($user['role'],'routine/set/index');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        if(!$id){
            ajaxReturn (404,'请求ID 为空');
        }
       $config= config_model::getConfigList($id);
       return $config;
    }
    // 修改系统配置信息
    function upConfigDetail($dt=[]){
        if(!is_array($dt)){
            ajaxReturn (404,'参数为空',$dt);
        }
        $user = isLogin();
        $logdt=$dt;
        $uid=$user['uid'];
        if(@$user['role_scope']!=1){
           ajaxReturn (460001,'账号没有数据权限');
        }
        $isqx=isAuthority($user['role'],'routine/set/editor');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        // return $dt;
        $isd=[];
        foreach($dt as $k => $v){
            $configDetail=Config_Model::getConfigDetail($k);
            $isdt=isModification($v,$configDetail);
            $logdt[$k]=$isdt;
            $dt=$isdt['newData'];
            if($v['type']=='json'){
                $dt['value']=json_encode($dt['value'],JSON_UNESCAPED_UNICODE);
            }
            if($v['type']=='upload'){
                if($v['input_type']!='image'){
                    $dt['value']=json_encode($dt['value'],JSON_UNESCAPED_UNICODE);
                }else{
                    if($v['upload_type']=='2'){
                        $dt['value']=json_encode($dt['value'],JSON_UNESCAPED_UNICODE);
                    }
                }
            }
            if(@array_key_exists("value",$dt)){
                $newdt=[
                    "value"=>$dt['value']    
                ];
                $isd[$k]=Config_Model::uploadConfigDetail($newdt,$k);
            }
        }
        // return $userDateil;
        $business_type='2';//2修改3删除
        $log_type="config";
        $log_title="修改了系统配置信息";
        
        $log_url='/admin/upConfigDetail';
        $log_data['token']=$user['token'];
        $log_data['data']=$logdt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($isd,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($isd?'成功':'失败');
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($isd?'0':'1'),$msg);

        return $isd;
    }
    // 获取系统配置一级分类
    function getOneConfigTab($isAll=false){
        $tabList=Config_Model::getConfigTabList();
        if($isAll){
            $newdt=[];
           foreach($tabList as $v){
               $v['title']='|----'.$v['title'];
                $newdt[]=$v;
               foreach ($v['children'] as $i => $d ){
                    $d['title']='|----|----'.$d['title'];
                    $newdt[]=$d;
                   
               }
            }
            return $newdt;
        }else{
            $newdt=[
                [ "id"=>'0', "title"=>"顶级分类", ]
            ];
            foreach($tabList as $v){
                unset($v['children']);
                $newdt[]=$v;
            }
            return $newdt;
        }
    }
    // 修改系统配置分类信息
    function uploadConfigTab($dt=[]){
        $user = isLogin();
        $uid=$user['uid'];
        if(@$user['role_scope']!=1){
           ajaxReturn (460001,'账号没有数据权限');
        }
        if(@$dt['isdel']){
            $isqx=isAuthority($user['role'],'maintain/exploit/configtab/del');
        }else{
            $isqx=isAuthority($user['role'],'maintain/exploit/configtab/editor');
        }
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        
        @$id=$dt['id'];
        if (empty($id)) {
            ajaxReturn (404,'参数为空',$dt);
        }
        
        unset($dt['id']);
        $oldDateil=Config_Model::getConfigTab($id);
        // return $roleDateil;
        // uploadRoleDetail
        $isdt=isModification($dt,$oldDateil);
        $isdt['id']=$id;
        
        $dt=$isdt['newData'];
        $dt['update_by']=$uid;
        // ajaxReturn(201,"数据没有修改,和新数据和原始数据一样",$dt);
        $up=Config_Model::uploadConfigTab($dt,$id);
        
        // return $up;
        $business_type='2';//2修改3删除
        $log_type="configtab";
        $log_title="修改系统配置分类[".$oldDateil['title']."]信息";
        if(@$dt['isdel']){
            $business_type='3';
            $log_title="删除系统配置分类[".$oldDateil['title']."]信息";
        }
        $log_url='/admin/upConfigTab';
        $log_data['token']=$user['token'];
        $log_data['data']=$isdt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($up,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($up?'成功':'失败');
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($up?'0':'1'),$msg);
        
        return $up;
        
    }
    // 新增配置分类信息
    function addConfigTab($dt=[]){
        $user = isLogin();
        $uid=$user['uid'];
        if(@$user['role_scope']!=1){
           ajaxReturn (460001,'账号没有数据权限');
        }
        $isqx=isAuthority($user['role'],'maintain/exploit/configtab/add');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        $fields=Config_Model::getConfigTabKey(@$dt['fields'])??true;
        if($fields){
            ajaxReturn (300,'已经有重复的字段'.$dt['fields'].'了',$dt);
        }
        if(!is_uname(@$dt['fields'])){
            ajaxReturn (205,'字段格式不正确,请换一个');
        }
        $dt['create_by']=$uid;
        $dt['update_by']=$uid;
        unset($dt['id']);
        $up=Config_Model::addConfigTab($dt);
        
        // return $up;
        $business_type='1';//2修改3删除
        $log_type="configtab";
        $log_title="新增系统配置分类[".$dt['title']."]信息";
        
        $log_url='/admin/addConfigTab';
        $log_data['token']=$user['token'];
        $log_data['data']=$dt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($up,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($up?'成功':'失败');
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($up?'0':'1'),$msg);
        
        return $up;
    }
    // 获取开发配置信息
    function getConfigDetail($id=''){
        $user = isLogin();
        $uid=$user['uid'];
        
        $isqx=isAuthority($user['role'],'maintain/exploit/config/index');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        if(!$id){
            ajaxReturn (404,'请求ID 为空');
        }
       $config= config_model::getConfigDetailList($id);
       $dt=[
           "list"=>$config,
           "tab"=>Config_Model::getConfigTab($id)
         ];
       return $dt;
    }
    
    // 新增配置信息
    function addConfigDetail($dt=[]){
        $user = isLogin();
        $uid=$user['uid'];
        if(@$user['role_scope']!=1){
           ajaxReturn (460001,'账号没有数据权限');
        }
        $isqx=isAuthority($user['role'],'maintain/exploit/config/add');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        $fields=Config_Model::getConfigDetail(@$dt['fields'])??true;
        if($fields){
            ajaxReturn (300,'已经有重复的字段'.$dt['fields'].'了',$dt);
        }
        if(!is_uname(@$dt['fields'])){
            ajaxReturn (205,'字段格式不正确,请换一个');
        }
        $dt['create_by']=$uid;
        $dt['update_by']=$uid;
        unset($dt['id']);
        if(@array_key_exists("value",$dt)){
            if(!is_string($dt['value'])){
                $dt['value']=json_encode($dt['value'],JSON_UNESCAPED_UNICODE);
            }
        }
        $up=Config_Model::addConfig($dt);
        
        // return $up;
        $business_type='1';//2修改3删除
        $log_type="config";
        $log_title="新增系统配置[".$dt['title']."]信息";
        
        $log_url='/admin/addConfig';
        $log_data['token']=$user['token'];
        $log_data['data']=$dt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($up,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($up?'成功':'失败');
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($up?'0':'1'),$msg);
        
        return $up;
    }
    // 修改配置信息
    function upConfig($dt=[]){
        if(!is_array($dt)){
            ajaxReturn (404,'参数为空',$dt);
        }
        $user = isLogin();
        $logdt=$dt;
        $uid=$user['uid'];
        if(@$user['role_scope']!=1){
           ajaxReturn (460001,'账号没有数据权限');
        }
        
        if(@$dt['isdel']){
            $isqx=isAuthority($user['role'],'maintain/exploit/config/del');
        }else{
            $isqx=isAuthority($user['role'],'maintain/exploit/config/editor');
        }
        
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        $fields=$dt['fields'];
        unset($dt['fields']);
        $oldDateil=Config_Model::getConfigDetail($fields);
        $isdt=isModification($dt,$oldDateil);
        $isdt['fields']=$fields;
        $dt=$isdt['newData'];
        $dt['update_by']=$uid;
        if(@array_key_exists("value",$dt)){
            if(!is_string($dt['value'])){
                $dt['value']=json_encode($dt['value'],JSON_UNESCAPED_UNICODE);
            }
        }
        
        $up =Config_Model::uploadConfigDetail($dt,$fields);
        // return $userDateil;
        $business_type='2';//2修改3删除
        $log_type="config";
        $log_title="修改了系统配置信息";
        if(@$dt['isdel']){
            $business_type='3';
            $log_title="删除系统配置[".$oldDateil['title']."]信息";
        }
        $log_url='/admin/upConfig';
        $log_data['token']=$user['token'];
        $log_data['data']=$isdt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($up,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($up?'成功':'失败');
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($up?'0':'1'),$msg);

        return $up;
    }
    
    // 新增组合数据
    function addGroup($dt){
        $user = isLogin();
        $uid=$user['uid'];
        if(@$user['role_scope']!=1){
           ajaxReturn (460001,'账号没有数据权限');
        }
        $isqx=isAuthority($user['role'],'maintain/exploit/group/add');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        $fields=Group_Model::getGroupDetailKey(@$dt['config_name'])??true;
        if($fields){
            ajaxReturn (300,'已经有重复的字段'.$dt['config_name'].'了',$dt);
        }
        if(!is_uname(@$dt['config_name'])){
            ajaxReturn (205,'字段格式不正确,请换一个');
        }
        $dt['create_by']=$uid;
        $dt['update_by']=$uid;
        unset($dt['id']);
        $up = Group_Model::addGroup($dt);
        
        // return $up;
        $business_type='1';//2修改3删除
        $log_type="group";
        $log_title="新增组合数据[".$dt['name']."]信息";
        
        $log_url='/admin/addGroup';
        $log_data['token']=$user['token'];
        $log_data['data']=$dt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($up,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($up?'成功':'失败');
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($up?'0':'1'),$msg);
        
        
        return $up;
    }
    // 获取组合数据列表
    function getGroupList($dt=[]){
        
        $pages="";
        $data="";
        if(@$dt['pages']){
            $pages=$dt['pages'];
        }
        if(@$dt['data']){
            $data=$dt['data'];
        }
        
        $user = isLogin();
        $uid=$user['uid'];
        
        $isqx=isAuthority($user['role'],'maintain/exploit/group/index');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        
        $list=Group_Model::getGroupList($pages,$data);
        
        return $list;
    }
    // 修改组合数据
    function upGroup($dt=[]){
        if(!is_array($dt)){
            ajaxReturn (404,'参数为空',$dt);
        }
        $user = isLogin();
        $logdt=$dt;
        $uid=$user['uid'];
        if(@$user['role_scope']!=1){
           ajaxReturn (460001,'账号没有数据权限');
        }
        
        if(@$dt['isdel']){
            $isqx=isAuthority($user['role'],'maintain/exploit/group/del');
        }else{
            $isqx=isAuthority($user['role'], 'maintain/exploit/group/editor');
        }
        
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        $id=$dt['id'];
        unset($dt['id']);
        $oldDateil=Group_Model::getGroupDetailId($id);
        $isdt=isModification($dt,$oldDateil);
        $isdt['id']=$id;
        $dt=$isdt['newData'];
        $dt['update_by']=$uid;
        
        // return $dt;
        $up =Group_Model::uploadGroup($dt,$id);
        // return $up;
        $business_type='2';//2修改3删除
        $log_type="group";
        $log_title="修改了组合数据";
        if(@$dt['isdel']){
            $business_type='3';
            $log_title="删除组合数据[".$oldDateil['name']."]信息";
        }
        $log_url='/admin/upGroup';
        $log_data['token']=$user['token'];
        $log_data['data']=$isdt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($up,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($up?'成功':'失败');
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($up?'0':'1'),$msg);

        return $up;
    }
    
    // 获取组合数据详情列表
    function getGroupDataList($dt=[]){
        
        $pages="";
        $data="";
        if(@$dt['pages']){
            $pages=$dt['pages'];
        }
        if(@$dt['data']){
            $data=$dt['data'];
        }
        
        $user = isLogin();
        $uid=$user['uid'];
        
        $isqx=isAuthority($user['role'],'maintain/exploit/grouplist/index');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        
        $list=Group_Model::getGroupDataList($pages,$data);
        return $list;
    }
      // 新增组合数据详情
    function addGroupData($dt){
        $user = isLogin();
        $uid=$user['uid'];
        if(@$user['role_scope']!=1){
           ajaxReturn (460001,'账号没有数据权限');
        }
        $isqx=isAuthority($user['role'],'maintain/exploit/grouplist/add');
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        $dt['create_by']=$uid;
        $dt['update_by']=$uid;
        unset($dt['id']);
        $up = Group_Model::addGroupData($dt);
        
        @$oldDateil=Group_Model::getGroupDetailId($dt['gid']);
        // return $up;
        $business_type='1';//2修改3删除
        $log_type="groupData";
        @$log_title="新增组合数据[".$oldDateil['name']."]详情";
        
        $log_url='/admin/addGroupData';
        $log_data['token']=$user['token'];
        $log_data['data']=$dt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($up,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($up?'成功':'失败');
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($up?'0':'1'),$msg);
        
        
        return $up;
    }
        // 修改组合数据详情
    function upGroupData($dt=[]){
        if(!is_array($dt)){
            ajaxReturn (404,'参数为空',$dt);
        }
        $user = isLogin();
        $logdt=$dt;
        $uid=$user['uid'];
        if(@$user['role_scope']!=1){
           ajaxReturn (460001,'账号没有数据权限');
        }
        
        if(@$dt['isdel']){
            $isqx=isAuthority($user['role'],'maintain/exploit/group/del');
        }else{
            $isqx=isAuthority($user['role'], 'maintain/exploit/group/editor');
        }
        
        if(@!$isqx){
           ajaxReturn (460000,'账号没有菜单权限');
        }
        $id=$dt['id'];
        unset($dt['id']);
        $oldDateil=Group_Model::getGroupDataDetail($id);
        $isdt=isModification($dt,$oldDateil);
        $isdt['id']=$id;
        $dt=$isdt['newData'];
        $dt['update_by']=$uid;
        
        // return $isdt;
        $up =Group_Model::uploadGroupData($dt,$id);
        // return $up;
        $business_type='2';//2修改3删除
        $log_type="groupData";
        $log_title="修改了组合数据详情";
        if(@$dt['isdel']){
            $business_type='3';
            $log_title="删除组合数据详情信息";
        }
        $log_url='/admin/upGroupData';
        $log_data['token']=$user['token'];
        $log_data['data']=$isdt;
        $log_data=json_encode($log_data,JSON_UNESCAPED_UNICODE);
        $json_result=json_encode($up,JSON_UNESCAPED_UNICODE);
        @$msg= '【'.$user['nickName'].'】'.$log_title.($up?'成功':'失败');
        @$caozuorz=addOperationLog($uid,$business_type,"1",$log_type,$log_title,$log_url,$log_data,$json_result,($up?'0':'1'),$msg);

        return $up;
    }
    
    function roleBtn(){
        $m=new Menu_Model();
        $DB=Database::getInstance();
        $roles = array();
        $query = $DB->query("SELECT * FROM `".DB_PREFIX."sys_role` ");
        while ($row = $DB->fetch_array($query)) {
            // $m=self::getrolemenu($row['role_id'])??[];
            $rolemenu = array();
            $q = $DB->query("SELECT * FROM `".DB_PREFIX."sys_role_menu` where `role_id`='".$row['role_id']."'");
            while ($v = $DB->fetch_array($q)) {
                $que=$DB->query("SELECT * FROM `".DB_PREFIX."sys_menu` where `menu_id`='".$v['menu_id']."' ");
                $m=false;
                while ($d = $DB->fetch_array($que)) {
                    if($d['menu_type']=="F"){
                        $m=$d['menu_name']; 
                    }
                }
                if($m){
                    $rolemenu[]=$m;
                }
            }
            $roles[$row['role_key']]=$rolemenu;
        }
        return $roles;
        return $roleBtn;
    }
    
?>